<style lang="less">
	.content {
		text-align: center;
		padding-top: 40upx;
	}
    .hader{
        margin:60upx 0 100upx 0;
    }
    .hader image{
        display: block;
        margin: 0 auto;
        width: 240upx;
    }
	.main{
		padding: 0 30upx;
		box-sizing: border-box;
	}
    .zhuce{
        border-bottom: 1upx solid rgba(221,221,221,1);
		overflow: hidden;
		.mobile{
			width: 65%;
			float: left;
		}
		input{
			line-height: 80upx;
			padding: 10upx;
			height: 80upx;
			font-size: 28upx;
			border: none;
			box-sizing: border-box;
			outline: none;
			text-align: left;
		}
    }
    .weixi{
        display: flex;
        justify-content:center;
        text-align: center;
        line-height: 60upx;
        color: #999999;
        font-size: 28upx;
        margin-top: 60upx;
    }
    .weixi image{
        width: 60upx;
        height: 60upx;
        margin: 0 0 0 20upx;
    }
    .but{
        display: block;
        width: 80%;
        margin: 100upx auto 0;
        line-height: 80upx;
        border-radius:40upx;
        background: #333333;
        color: #FFFFFF;
        text-align: center;
    }
	// picker{
	//   float: left;
	// }
	.picker{
	  float: left;
	  margin-right:10upx;
	  line-height: 80upx;
	  .picker-img{
	    width: 22upx;
		margin-left: 10upx;
	  }
	}
</style>
<template>
	<view class="content">
		<view class="hader">
		    <image src="/static/img/login.png" mode="widthFix"></image>
		</view>
		<view class="main">
			<view class="zhuce">
				<view class="picker" v-if="array!=''" @tap="bindPickerChange">
					{{array.areaCode}}({{array.country}})
					<image src="/static/img/arrowup_icons@2x.png" class="picker-img" mode="widthFix"></image>
				</view>
				<input type="text" maxlength="11" class="mobile" v-model="mobile" placeholder="请输入手机号" @input="onKeyUserNameInput" id="mobile" /> 
			</view>
			<view class="zhuce"><input type="password" class="password" v-model="password" name="" @input="passwordInput" id="password" placeholder="请输入密码" maxlength="30"></view>
			<view class="but" id="showTooltips" @tap="showTooltips">登录</view>
			<view class="weixi"><text>微信授权登录</text><image src="/static/img/wechat_login.png" mode="widthFix" @tap="onGotUserInfo"></image></view>
		</view>
	</view>
</template>

<script>
	import api from '@/common/api';
	export default {
		data() {
			return {
				mobile: "",  
				password: "",
				array:{
				  areaCode:'+86',
				  country:'中国',
				  firstLetter:'Z',
				  sort:'10'
				},
				isClose:true//判断当前页面是打开还是返回页
			}
		},
		onLoad() {
		},
		onShow() {
		   if(this.isClose==false){
		     var pages = getCurrentPages();
		     var currPage = pages[pages.length - 1];
		     if(currPage.array!=undefined){
		       this.array=currPage.array
		     }
		   }
		},
		onHide(){
		   this.isClose=false
		},
		methods: {
			async login(){
				const [err, res] = await api.login({
					query: {
						 mobile:this.mobile,
						 password :this.password,
						 areaCode:this.array.areaCode
					}
				 });
				 if(res.data.code == 0){
					 let token=res.data.data.token
					 uni.setStorageSync('token', token);
					// let url=uni.getStorageSync('url')
					// if(url!='' && url!=null){
					// 	uni.reLaunch({
					// 	  url: '/'+url+''
					// 	})
					// }else{
					// 	uni.reLaunch({
					// 	  url: "/pages/newData/capital"
					// 	})
					// }
					uni.reLaunch({
					  url: "/pages/newData/capital?type=1"
					})
					
				 }else{
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					})
				 }
			},
			bindPickerChange() {
				uni.navigateTo({
				  url: "/pages/login/selectCountry"
				})
			 },
			 onKeyUserNameInput(e) {  
                this.mobile = e.target.value  
            }, 
			 passwordInput(e){
				 this.password = e.target.value  
			 },
			showTooltips(){
				this.login()
			},
			onGotUserInfo(){
				// let url=uni.getStorageSync('url')
				// let href=encodeURIComponent('https://h5.xpandago.net/wechat/index.html#/'+url);
				let hrefUrl=encodeURIComponent('https://h5.xpandago.net/wechat/index.html#/pages/newData/capital')
				// console.log(href)
				// if(url!='' && url!=null){
				// 	location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd242cbb43e8c6351&redirect_uri='+href+'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'

				// }else{
				// 	location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd242cbb43e8c6351&redirect_uri='+hrefUrl+'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'
				// }
					location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd242cbb43e8c6351&redirect_uri='+hrefUrl+'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'
			}
		}
	}
</script>
